package com.jeeplus.test.jlnu.studentStatusInfo.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.test.jlnu.archivalInfo.domain.entity.ArchParmerter;
import com.jeeplus.test.jlnu.studentStatusInfo.domain.entity.StudentStatusInfo;
import com.jeeplus.test.jlnu.studentStatusInfo.domain.vo.StudentStatusInfoReqVo;
import org.apache.ibatis.annotations.*;

@Mapper
public interface StudentStatusInfoMapper {

    @Select({
            "<script>",
            "SELECT st.*,",
            "       ad.archival_num AS archivalNum,",
            "       ad.case_title AS caseTitle,",
            "       ad.file_title AS fileTitle,",
            "       ad.save_location AS saveLocation,",
            "       ad.page_location AS pageLocation,",
            "       ad.page_num AS pageNum,",
            "       ad.examinee_num AS examineeNum,",
            "       ad.admission_num AS admissionNum,",
            "       ad.student_id AS studentId,",
            "       ad.name AS name,",
            "       ad.gender AS gender,",
            "       ad.birthday AS birthday,",
            "       ad.political_outlook AS politicalOutlook,",
            "       ad.nation AS nation,",
            "       ad.id_card AS idCard,",
            "       ad.plan_nature AS planNature,",
            "       ad.admission_schools AS admissionSchools,",
            "       ad.admission_academy AS admissionAcademy,",
            "       ad.admission_major AS admissionMajor,",
            "       ad.admission_time AS admissionTime,",
            "       ad.gradation AS gradation,",
            "       ad.educational_system AS educationalSystem,",
            "       ad.learning_forms AS learningForms,",
            "       ad.examinee_sort AS examineeSort,",
            "       ad.batch AS batch,",
            "       ad.graduation_school AS graduationSchool,",
            "       ad.source_area AS sourceArea,",
            "       ad.area_name AS areaName,",
            "       ad.home_address AS homeAddress,",
            "       ad.postal_code AS postalCode,",
            "       ad.phone_num AS phoneNum,",
            "       ad.info_source AS infoSource,",
            "       ad.remarks AS remarks,",
            "       ad.ext1 AS ext1,",
            "       ad.ext2 AS ext2,",
            "       ad.ext3 AS ext3,",
            "       ad.ext4 AS ext4,",
            "       ad.ext5 AS ext5,",
            "       ad.ext6 AS ext6,",
            "       ad.ext7 AS ext7,",
            "       ad.ext8 AS ext8,",
            "       ad.ext9 AS ext9,",
            "       ad.ext10 AS ext10,",
            "       ad.ext11 AS ext11,",
            "       ad.ext12 AS ext12,",
            "       ad.ext13 AS ext13,",
            "       ad.ext14 AS ext14,",
            "       ad.ext15 AS ext15,",
            "       ad.ext16 AS ext16,",
            "       ad.ext17 AS ext17,",
            "       ad.ext18 AS ext18,",
            "       ad.ext19 AS ext19,",
            "       ad.ext20 AS ext20",
            "FROM jlnu_student_status_info st",
            "LEFT JOIN jlnu_admission_info ad ON st.student_id = ad.student_id",
            "WHERE 1=1",
            "<if test='studentStatusInfoReqVo.name != null and studentStatusInfoReqVo.name != \"\"'>",
            "AND ad.name = #{studentStatusInfoReqVo.name}",
            "</if>",
            "<if test='studentStatusInfoReqVo.studentId != null and studentStatusInfoReqVo.studentId != \"\"'>",
            "AND ad.student_id = #{studentStatusInfoReqVo.studentId}",
            "</if>",
            "<if test='studentStatusInfoReqVo.admissionAcademy != null and studentStatusInfoReqVo.admissionAcademy != \"\"'>",
            "AND ad.admission_academy = #{studentStatusInfoReqVo.admissionAcademy}",
            "</if>",
            "<if test='studentStatusInfoReqVo.admissionMajor != null and studentStatusInfoReqVo.admissionMajor != \"\"'>",
            "AND ad.admission_major = #{studentStatusInfoReqVo.admissionMajor}",
            "</if>",
            "<if test='studentStatusInfoReqVo.phoneNum != null and studentStatusInfoReqVo.phoneNum != \"\"'>",
            "AND ad.phone_num = #{studentStatusInfoReqVo.phoneNum}",
            "</if>",
            "</script>"
    })
    Page<StudentStatusInfo> getStudentStatusInfoPage(ArchParmerter studentStatusInfoReqVo, Page<StudentStatusInfo> page);

    @Update({
            "<script>",
            "UPDATE jlnu_student_status_info",
            "<set>",
            "<if test='studentStatusInfoReqVo.age != null and studentStatusInfoReqVo.age != \"\"'>age = #{studentStatusInfoReqVo.age},</if>",
            "<if test='studentStatusInfoReqVo.grade != null and studentStatusInfoReqVo.grade != \"\"'>grade = #{studentStatusInfoReqVo.grade},</if>",
            "<if test='studentStatusInfoReqVo.classId != null and studentStatusInfoReqVo.classId != \"\"'>class_id = #{studentStatusInfoReqVo.classId},</if>",
            "<if test='studentStatusInfoReqVo.entranceDate != null'>entrance_date = #{studentStatusInfoReqVo.entranceDate},</if>",
            "<if test='studentStatusInfoReqVo.expectedGraduationDate != null'>expected_graduation_date = #{studentStatusInfoReqVo.expectedGraduationDate},</if>",
            "<if test='studentStatusInfoReqVo.majorCode != null and studentStatusInfoReqVo.majorCode != \"\"'>major_code = #{studentStatusInfoReqVo.majorCode},</if>",
            "<if test='studentStatusInfoReqVo.details != null and studentStatusInfoReqVo.details != \"\"'>details = #{studentStatusInfoReqVo.details},</if>",
            "<if test='studentStatusInfoReqVo.changeDate != null'>change_date = #{studentStatusInfoReqVo.changeDate},</if>",
            "<if test='studentStatusInfoReqVo.changeSort != null and studentStatusInfoReqVo.changeSort != \"\"'>change_sort = #{studentStatusInfoReqVo.changeSort},</if>",
            "<if test='studentStatusInfoReqVo.changeContent != null and studentStatusInfoReqVo.changeContent != \"\"'>change_content = #{studentStatusInfoReqVo.changeContent},</if>",
            "<if test='studentStatusInfoReqVo.nameBeforeChange != null and studentStatusInfoReqVo.nameBeforeChange != \"\"'>name_before_change = #{studentStatusInfoReqVo.nameBeforeChange},</if>",
            "<if test='studentStatusInfoReqVo.nameChanged != null and studentStatusInfoReqVo.nameChanged != \"\"'>name_changed = #{studentStatusInfoReqVo.nameChanged},</if>",
            "<if test='studentStatusInfoReqVo.responsiblePerson != null and studentStatusInfoReqVo.responsiblePerson != \"\"'>responsible_person = #{studentStatusInfoReqVo.responsiblePerson},</if>",
            "<if test='studentStatusInfoReqVo.dateTime != null'>date_time = #{studentStatusInfoReqVo.dateTime},</if>",
            "<if test='studentStatusInfoReqVo.standards != null and studentStatusInfoReqVo.standards != \"\"'>standards = #{studentStatusInfoReqVo.standards},</if>",
            "<if test='studentStatusInfoReqVo.quantity != null'>quantity = #{studentStatusInfoReqVo.quantity},</if>",
            "<if test='studentStatusInfoReqVo.pageCount != null'>page_count = #{studentStatusInfoReqVo.pageCount},</if>",
            "<if test='studentStatusInfoReqVo.archiveUnit != null and studentStatusInfoReqVo.archiveUnit != \"\"'>archive_unit = #{studentStatusInfoReqVo.archiveUnit},</if>",
            "<if test='studentStatusInfoReqVo.transferor != null and studentStatusInfoReqVo.transferor != \"\"'>transferor = #{studentStatusInfoReqVo.transferor},</if>",
            "<if test='studentStatusInfoReqVo.receiver != null and studentStatusInfoReqVo.receiver != \"\"'>receiver = #{studentStatusInfoReqVo.receiver},</if>",
            "<if test='studentStatusInfoReqVo.transferTime != null'>transfer_time = #{studentStatusInfoReqVo.transferTime},</if>",
            "</set>",
            "WHERE student_id = #{studentStatusInfoReqVo.studentId}",
            "</script>"
    })
    int updateStudentStatus(@Param("studentStatusInfoReqVo") StudentStatusInfoReqVo studentStatusInfoReqVo);

    void updateAdmission(String grade, String applyNow, String studentId);


    @Insert("INSERT INTO jlnu_student_status_info (student_id, age, grade, class_id, entrance_date, expected_graduation_date, major_code, details, change_date, change_sort, change_content, name_before_change, name_changed, responsible_person, date_time, standards, quantity, page_count, archive_unit, transferor, receiver, transfer_time) " +
            "VALUES (#{studentId}, #{age}, #{grade}, #{classId}, #{entranceDate}, #{expectedGraduationDate}, #{majorCode}, #{details}, #{changeDate}, #{changeSort}, #{changeContent}, #{nameBeforeChange}, #{nameChanged}, #{responsiblePerson}, #{dateTime}, #{standards}, #{quantity}, #{pageCount}, #{archiveUnit}, #{transferor}, #{receiver}, #{transferTime})")
    void addStudentInfo(StudentStatusInfoReqVo studentStatusInfoReqVo);


}
